package com.sdy.dcsb.biz.service.impl;

import com.sdy.dcsb.biz.mapper.UserOperationLogMapper;
import com.sdy.dcsb.biz.model.UserOperationLog;
import com.sdy.dcsb.biz.service.SUserService;
import com.sdy.dcsb.biz.service.UserOperationLogService;
import com.sdy.mvc.service.impl.BaseServiceImpl;
import com.sdy.mvc.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 * 操作记录记录表 服务实现类
 * </p>
 *
 * @author fb
 * @since 2019/11/27
 */
@Slf4j
@Service
public class UserOperationLogServiceImpl extends BaseServiceImpl<UserOperationLog> implements UserOperationLogService{
    @Autowired
    private UserOperationLogMapper userOperationLogMapper;
    @Autowired
    private UserOperationLogService userOperationLogService;
    @Autowired
    private SUserService sUserService;

    @Override
    public void savaUserLog(HttpServletRequest request, String operationName, String operationInfo) {
        String ip = HttpUtil.getIpAddr(request);
        UserOperationLog userOperationLog =  new UserOperationLog();
        userOperationLog.setOperationName(operationName);
        userOperationLog.setOperationTime(new Date());
        userOperationLog.setOperationIp(ip);
        userOperationLog.setOperationInfo(operationInfo);
        userOperationLogService.save(userOperationLog);
    }
    @Override
    public void savaUserLog(HttpServletRequest request, String operationInfo) {
        String ip = HttpUtil.getIpAddr(request);
        UserOperationLog userOperationLog = new UserOperationLog();
        userOperationLog.setOperationName(sUserService.getUser(request));
        userOperationLog.setOperationTime(new Date());
        userOperationLog.setOperationIp(ip);
        userOperationLog.setOperationInfo(operationInfo);
        userOperationLogService.save(userOperationLog);
    }

}
